package com.jy.modules.cims.interact;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.fasterxml.jackson.core.type.TypeReference;
import com.jy.modules.cims.common.CimsConstant;
import com.jy.modules.cims.common.CimsIrtUrlConstant;
import com.jy.modules.cims.common.exception.CimsExceptionConstant;
import com.jy.modules.cims.common.exception.InteractException;
import com.jy.modules.cims.common.sysUtils.CollectionsUtils;
import com.jy.modules.cims.common.sysUtils.InteractUtil;
import com.jy.modules.cims.common.sysUtils.SimpleStringUtils;
import com.jy.modules.cims.data.common.dto.TCMmContractConstraintDTO;
import com.jy.modules.cims.data.common.dto.TCMmCreditDetailDTO;
import com.jy.modules.cims.data.dto.ApproveConfirmResultDto;
import com.jy.modules.cims.data.dto.ConfirmParamDto;
import com.jy.modules.cims.data.dto.CreditDetailDto;
import com.jy.modules.cims.data.dto.CustInfoDto;
import com.jy.modules.cims.data.dto.InteractEnsureDto;
import com.jy.modules.cims.data.dto.QuotaApplyParamDto;
import com.jy.modules.cims.data.dto.QuotaApplyResultDto;
import com.jy.modules.cims.data.dto.QuotaCreditRightDto;
import com.jy.modules.cims.data.dto.QuotaDetailUnlockParamDto;
import com.jy.modules.cims.data.dto.QuotaDetailUnlockResultDto;
import com.jy.modules.cims.data.dto.QuotaDto;
import com.jy.modules.cims.data.dto.credit.AutoPretendParamDto;
import com.jy.modules.cims.data.dto.credit.AutoPretendResultDto;
import com.jy.modules.cims.data.dto.credit.BatchCreditQueryDto;
import com.jy.modules.cims.data.dto.credit.BatchCreditQueryResultDto;
import com.jy.modules.cims.data.dto.credit.BatchCreditTranferListDTO;
import com.jy.modules.cims.data.dto.credit.CreditRedeemSettleDto;
import com.jy.modules.cims.data.dto.credit.CreditRepayPlanQueryDto;
import com.jy.modules.cims.data.dto.credit.CreditRepayPlanQueryResultDto;
import com.jy.modules.cims.data.dto.credit.CreditTwoBuyMatchDto;
import com.jy.modules.cims.data.dto.credit.CreditTwoBuyRepayDto;
import com.jy.modules.cims.data.dto.credit.CreditTwoBuySettleDto;
import com.jy.modules.cims.data.dto.credit.CreditValueCalculateDto;
import com.jy.modules.cims.data.dto.credit.CreditValueCalculateResultDto;
import com.jy.modules.cims.data.dto.credit.CreditVrMonthRepayDto;
import com.jy.modules.cims.data.dto.credit.PublicInfoQueryDto;
import com.jy.modules.cims.data.dto.credit.PublicInfoQueryResult;
import com.jy.modules.cims.data.dto.credit.PublicSettleParamDto;
import com.jy.modules.cims.data.dto.credit.PublicSettleResultDto;
import com.jy.modules.cims.data.dto.credit.RedeemParamDto;
import com.jy.modules.cims.data.dto.credit.RedeemResultDto;
import com.jy.modules.cims.data.dto.credit.SettleResult;
import com.jy.modules.cims.data.dto.credit.SettleResultDto;
import com.jy.modules.cims.data.interact.core.credit.request.Request4011DTO;
import com.jy.modules.cims.data.interact.core.credit.request.Request4016DTO;
import com.jy.modules.cims.data.interact.core.credit.request.Request4021DTO;
import com.jy.modules.cims.data.interact.core.credit.request.Request4022DTO;
import com.jy.modules.cims.data.interact.core.credit.request.Request4023DTO;
import com.jy.modules.cims.data.interact.core.credit.request.Request4024DTO;
import com.jy.modules.cims.data.interact.core.credit.request.Request4025DTO;
import com.jy.modules.cims.data.interact.core.credit.request.Request4026DTO;
import com.jy.modules.cims.data.interact.core.credit.request.Request4027DTO;
import com.jy.modules.cims.data.interact.core.credit.request.Request4028DTO;
import com.jy.modules.cims.data.interact.core.credit.request.Request4029DTO;
import com.jy.modules.cims.data.interact.core.credit.request.Request4035DTO;
import com.jy.modules.cims.data.interact.core.credit.request.Request4036DTO;
import com.jy.modules.cims.data.interact.core.credit.request.Request4040DTO;
import com.jy.modules.cims.data.interact.core.credit.request.Request4041DTO;
import com.jy.modules.cims.data.interact.core.credit.request.Request4042DTO;
import com.jy.modules.cims.data.interact.core.credit.request.Request4043DTO;
import com.jy.modules.cims.data.interact.core.credit.request.Request4046DTO;
import com.jy.modules.cims.data.interact.core.credit.request.Request4050DTO;
import com.jy.modules.cims.data.interact.core.credit.request.RequestApplyIdDTO;
import com.jy.modules.cims.data.interact.core.credit.request.RequestCashRepayDTO;
import com.jy.modules.cims.data.interact.core.credit.request.RequestCkDataListDTO;
import com.jy.modules.cims.data.interact.core.credit.request.RequestCreditSettlementEarlyDTO;
import com.jy.modules.cims.data.interact.core.credit.request.RequestCreditTransferVirtualRepayDTO;
import com.jy.modules.cims.data.interact.core.credit.request.RequestCreditValueDTO;
import com.jy.modules.cims.data.interact.core.credit.request.RequestMatchCreditDTO;
import com.jy.modules.cims.data.interact.core.credit.request.RequestRepaymentDTO;
import com.jy.modules.cims.data.interact.core.credit.request.RequestSettleDTO;
import com.jy.modules.cims.data.interact.core.credit.request.RequestTranferListDTO;
import com.jy.modules.cims.data.interact.core.credit.request.RequestTransferDTO;
import com.jy.modules.cims.data.interact.core.credit.response.Response4011DTO;
import com.jy.modules.cims.data.interact.core.credit.response.Response4016DTO;
import com.jy.modules.cims.data.interact.core.credit.response.Response4021DTO;
import com.jy.modules.cims.data.interact.core.credit.response.Response4022DTO;
import com.jy.modules.cims.data.interact.core.credit.response.Response4023DTO;
import com.jy.modules.cims.data.interact.core.credit.response.Response4024DTO;
import com.jy.modules.cims.data.interact.core.credit.response.Response4025DTO;
import com.jy.modules.cims.data.interact.core.credit.response.Response4026DTO;
import com.jy.modules.cims.data.interact.core.credit.response.Response4027DTO;
import com.jy.modules.cims.data.interact.core.credit.response.Response4028DTO;
import com.jy.modules.cims.data.interact.core.credit.response.Response4029DTO;
import com.jy.modules.cims.data.interact.core.credit.response.Response4035DTO;
import com.jy.modules.cims.data.interact.core.credit.response.Response4036DTO;
import com.jy.modules.cims.data.interact.core.credit.response.Response4040DTO;
import com.jy.modules.cims.data.interact.core.credit.response.Response4041DTO;
import com.jy.modules.cims.data.interact.core.credit.response.Response4042DTO;
import com.jy.modules.cims.data.interact.core.credit.response.Response4043DTO;
import com.jy.modules.cims.data.interact.core.credit.response.Response4046DTO;
import com.jy.modules.cims.data.interact.core.credit.response.Response4050DTO;
import com.jy.modules.cims.data.interact.core.credit.response.ResponseCreditValueDTO;
import com.jy.modules.cims.data.interact.core.credit.response.ResponseCreditsDTO;
import com.jy.modules.cims.data.interact.core.loan.request.Request4038DTO;
import com.jy.modules.cims.data.interact.core.loan.request.Request4039DTO;
import com.jy.modules.cims.data.interact.core.loan.request.Request4044DTO;
import com.jy.modules.cims.data.interact.core.loan.request.RequestCreditRedemptionDTO;
import com.jy.modules.cims.data.interact.core.loan.request.RequestCreditSettlementDTO;
import com.jy.modules.cims.data.interact.core.loan.request.RequestRedeemDTO;
import com.jy.modules.cims.data.interact.core.loan.response.Response4038DTO;
import com.jy.modules.cims.data.interact.core.loan.response.Response4039DTO;
import com.jy.modules.cims.data.interact.core.loan.response.Response4044DTO;
import com.jy.modules.cims.data.interact.funds.RequestFundsRiskDTO;
import com.jy.modules.cims.data.interact.funds.ResponseFundsRiskDTO;
import com.jy.modules.cims.data.interact.funds.request.Request4051DTO;
import com.jy.modules.cims.data.interact.funds.response.Response4051DTO;
import com.jy.platform.core.message.ResponseMsg;

/**
 * 
 * <b>类名称：</b>CIRCreditPoolIFImpl <br/>
 * <b>类描述：债权相关交互实现类</b><br/>
 * <b>创建人：</b>chenguixue<br/>
 * <b>修改人：</b><br/>
 * <b>修改时间：</b>2015-1-22 上午10:05:44<br/>
 * <b>修改备注：</b><br/>
 * <b>版本信息：</b>v1.0.0<br/>
 */
@Service("com.jy.modules.cims.interact.CIRCreditPoolIFImpl")
public class CIRCreditPoolIFImpl {

    private static final Logger logger = LoggerFactory.getLogger(CIRCreditPoolIFImpl.class);

    @Autowired
    @Qualifier("com.jy.modules.cims.interact.InteractClient")
    public InteractClient interactClient;

    @Autowired
	@Qualifier("com.jy.modules.cims.interact.CInteractAssist")
	public IInteractAssist iInteractAssist;
    /**
     * 债权额度申请
     * 
     * @param paramDto
     * @return
     * @author chenguixue
     * @date 2015-1-22-上午10:13:39
     * @update
     */
    public QuotaApplyResultDto quotaApply(QuotaApplyParamDto paramDto) {

        Request4024DTO req = new Request4024DTO();
        QuotaDto quotaDto = paramDto.getQuotaDto();
        req.setInterfaceNo((String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_QUOTAAPPLY_CREDIT).get(
                CimsIrtUrlConstant.IRT_CODE));
        req.setBusiCode((String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_QUOTAAPPLY_CREDIT).get(
                CimsIrtUrlConstant.IRT_BUSICODE));
        req.setApplyId(quotaDto.getQuotaCode());
        req.setStartDate(quotaDto.getStartDate());
        req.setEndDate(quotaDto.getInvalidDate());
        req.setApplyTotalValue(quotaDto.getQuotaSum());
        req.setApplyState(CimsIrtUrlConstant.IRT_QUOTAAPPLY_CREDIT_TYPE_NEW);
        req.setOrgCode(quotaDto.getCooperorgCode());
        req.setCaculateDate(quotaDto.getCreditReferDate());
        req.setTransferedTotalValue(new BigDecimal(0)); // 写死即可

        // 组装债权约束条件
        List<RequestCkDataListDTO> ckDataList = new ArrayList<RequestCkDataListDTO>();
        req.setCkDataList(ckDataList);
        List<TCMmContractConstraintDTO> list = paramDto.getContractConstraintDtoList();
        if (list != null) {
            for (TCMmContractConstraintDTO value : list) {
                RequestCkDataListDTO cc = new RequestCkDataListDTO();
                cc.setConstraintCode(value.getConstraintCode());
                cc.setConstraintName(value.getConstraintName());
                cc.setConstraintValues(value.getConstraintValues());
                cc.setScopeEquation(value.getScopeEquation());
                ckDataList.add(cc);
            }
        }
        InteractEnsureDto ensureDto = new InteractEnsureDto();
        ensureDto.setDealCode(quotaDto.getQuotaCode());
        Response4024DTO responseMsg = interactClient.sendReqToCore(
                (String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_QUOTAAPPLY_CREDIT).get(
                        CimsIrtUrlConstant.IRT_URL), req, new TypeReference<ResponseMsg<Response4024DTO>>() {},
                ensureDto);
        if (responseMsg != null)
            return QuotaApplyResultDto.successQuotaApplyResultDto();
        return null;
    }

    /**
     * 债权额度取消
     * 
     * @param paramDto
     * @return
     * @author chenguixue
     * @date 2015-1-22-上午10:13:39
     * @update
     */
    public QuotaApplyResultDto quotaCancel(QuotaApplyParamDto paramDto) {

    	String backType = SimpleStringUtils.hasText(paramDto.getBackType())?paramDto.getBackType():CimsConstant.QUOTABACK_01;
        Request4027DTO req = new Request4027DTO();
        QuotaDto quotaDto = paramDto.getQuotaDto();
        req.setInterfaceNo((String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_QUOTAAPPLY_CREDIT_CANCEL)
                .get(CimsIrtUrlConstant.IRT_CODE));
        req.setBusiCode((String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_QUOTAAPPLY_CREDIT_CANCEL)
                .get(CimsIrtUrlConstant.IRT_BUSICODE));

        List<RequestApplyIdDTO> batchList = new ArrayList<RequestApplyIdDTO>();
        RequestApplyIdDTO dto = new RequestApplyIdDTO();
        dto.setApplyId(quotaDto.getQuotaCode());
        dto.setBackType(backType);
        batchList.add(dto);

        req.setApplyIdList(batchList);

        InteractEnsureDto ensureDto = new InteractEnsureDto();
        ensureDto.setDealCode(paramDto.getDealCode());
        Response4027DTO responseMsg = interactClient.sendReqToCore(
                (String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_QUOTAAPPLY_CREDIT_CANCEL).get(
                        CimsIrtUrlConstant.IRT_URL), req, new TypeReference<ResponseMsg<Response4027DTO>>() {},
                ensureDto);

        if (responseMsg != null)
            return QuotaApplyResultDto.successQuotaApplyResultDto();
        return null;
    }

    /**
     * 
     * @Title quotaUnlock
     * @Description 合作机构债权转让释放
     * @param creditDetailList
     * @return Response4021DTO
     * @author lixinyao
     * @date 2015-1-22-下午3:37:34
     * @update
     * @throws
     */
    public QuotaDetailUnlockResultDto quotaDetailUnlock(QuotaDetailUnlockParamDto paramDto) {
        Request4021DTO req = new Request4021DTO();
        req.setFrontTransNo(paramDto.getDealCode());
        List<QuotaDetailUnlockParamDto.CreditRightUnlockInfo> unlockList = paramDto.getCreditRightUnlockList();
        req.setInterfaceNo((String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_CREDIT_UNLOCK).get(
                CimsIrtUrlConstant.IRT_CODE));
        req.setBusiCode((String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_CREDIT_UNLOCK).get(
                CimsIrtUrlConstant.IRT_BUSICODE));

        if (unlockList == null || unlockList.isEmpty()) {
            logger.info(CimsExceptionConstant.INTERACT_CREDIT_UNLOCK_LIST_EMPTY);
            QuotaDetailUnlockResultDto quotaDetailUnlockResultDto = QuotaDetailUnlockResultDto
                    .successQuotaDetailUnlockResultDto();
            quotaDetailUnlockResultDto.setCreditList(null);
            return quotaDetailUnlockResultDto;
        }

        List<RequestTransferDTO> transferList = new ArrayList<RequestTransferDTO>(unlockList.size());
        // 生成释放债权request列表
        RequestTransferDTO transferDto = null;
		for (QuotaDetailUnlockParamDto.CreditRightUnlockInfo creditRightUnlock : unlockList) {
			if (CimsConstant.CREDIT_NOWHOLE.equals(creditRightUnlock.getIsWhole())
					&& creditRightUnlock.getFreeValue().compareTo(BigDecimal.ZERO) <= 0) {
				continue;
			}
			transferDto = new RequestTransferDTO();
			transferDto.setTransferId(creditRightUnlock.getTransferId());
			transferDto.setCreditId(creditRightUnlock.getCreditId());
			transferDto.setEachRepaymentValue(creditRightUnlock.getEachRepaymentValue());
			transferDto.setFreeValue(creditRightUnlock.getFreeValue());
			transferDto.setIsWhole(creditRightUnlock.getIsWhole());
			transferDto.setDeliveryDate(creditRightUnlock.getDeliveryDate());// 债权释放接口增加释放日期，释放标的日的债权价值
			transferList.add(transferDto);
		}
		if (CollectionsUtils.isEmpty(transferList)) {
			 return null;
		}
		
        req.setTransferList(transferList);
        InteractEnsureDto ensureDto = new InteractEnsureDto();
        ensureDto.setDealCode(paramDto.getDealCode());
        Response4021DTO responseMsg = interactClient.sendReqToCore(
                (String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_CREDIT_UNLOCK).get(
                        CimsIrtUrlConstant.IRT_URL), req, new TypeReference<ResponseMsg<Response4021DTO>>() {},
                ensureDto);
        if (responseMsg != null) {
            QuotaDetailUnlockResultDto quotaDetailUnlockResultDto = QuotaDetailUnlockResultDto
                    .successQuotaDetailUnlockResultDto();
            quotaDetailUnlockResultDto.setCreditList(responseMsg.getCreditList());
            return quotaDetailUnlockResultDto;
        }
        return null;
    }

    /**
     * 
     * @Title confirmCreditRightTransfer
     * @Description 合作机构转让结果确认
     * @param creditDetailList
     * @return Response4022DTO
     * @author lixinyao
     * @date 2015-1-22-下午3:40:47
     * @update
     * @throws
     */
    public ApproveConfirmResultDto confirmCreditRightTransfer(ConfirmParamDto confirmDto) {
        Request4022DTO req = new Request4022DTO();
        req.setFrontTransNo(confirmDto.getFrontTransNo());
        req.setInterfaceNo((String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_CREDIT_APPROVE).get(
                CimsIrtUrlConstant.IRT_CODE));
        req.setBusiCode((String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_CREDIT_APPROVE).get(
                CimsIrtUrlConstant.IRT_BUSICODE));

        List<ConfirmParamDto.CreditRightInfo> creditDetailList = confirmDto.getCreditRightList();
        req.setBatchId(confirmDto.getDealCode());
        req.setCCode(confirmDto.getCooperorgCode());
        if (creditDetailList == null || creditDetailList.isEmpty()) {
            logger.info(CimsExceptionConstant.INTERACT_CREDIT_APPROVECONFIRM_LIST_EMPTY);
            return ApproveConfirmResultDto.successApproveConfirmResultDto();
        }
        List<RequestTransferDTO> transferList = new ArrayList<RequestTransferDTO>(creditDetailList.size());
        // 生成确认债权request列表
        for (ConfirmParamDto.CreditRightInfo creditRight : creditDetailList) {
            RequestTransferDTO transferDto = new RequestTransferDTO();
            transferDto.setTransferId(creditRight.getTransferId());
            transferDto.setCreditId(creditRight.getCreditId());
            transferDto.setContractNo(creditRight.getContractNo());
            transferDto.setDeliveryDate(creditRight.getDeliveryDate());
            transferDto.setRepaymentAffiliation(confirmDto.getCreditAffiliation());
            transferList.add(transferDto);
        }
        req.setTransferList(transferList);
        InteractEnsureDto ensureDto = new InteractEnsureDto();
        ensureDto.setDealCode(confirmDto.getDealCode());
        Response4022DTO responseMsg = interactClient.sendReqToCore(
                (String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_CREDIT_APPROVE).get(
                        CimsIrtUrlConstant.IRT_URL), req, new TypeReference<ResponseMsg<Response4022DTO>>() {},
                ensureDto);
        if (responseMsg != null) {
            ApproveConfirmResultDto approveConfirmResultDto = ApproveConfirmResultDto.successApproveConfirmResultDto();
            approveConfirmResultDto.setCreditList(responseMsg.getCreditList());
            return approveConfirmResultDto;
        }
        return null;
    }

    /**
     * 
     * @Title redeemCreditRight
     * @Description 合作机构转让批量赎回
     * @param creditDetailList
     * @return Response4023DTO
     * @author lixinyao
     * @date 2015-1-22-下午3:51:09
     * @update
     * @throws
     */
    public RedeemResultDto redeemCreditRight(RedeemParamDto redeemParamDto) {
        Request4023DTO req = new Request4023DTO();
        List<CreditDetailDto> creditDetailList = redeemParamDto.getCreditDetailList();
        req.setInterfaceNo((String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_CREDIT_REDEEM).get(
                CimsIrtUrlConstant.IRT_CODE));
        req.setBusiCode((String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_CREDIT_REDEEM).get(
                CimsIrtUrlConstant.IRT_BUSICODE));
        req.setFrontTransNo(redeemParamDto.getFrontTransNo());
        req.setBatchId(redeemParamDto.getDealCode());//交易流水号
        req.setCCode(redeemParamDto.getCCode());//合作机构编号
        req.setBizType(redeemParamDto.getBizType());//业务类型
        if (creditDetailList == null || creditDetailList.isEmpty()) {
            logger.info(CimsExceptionConstant.INTERACT_CREDIT_REDEEM_LIST_EMPTY);
            return RedeemResultDto.successRedeemResultDto();
        }

        // 生成释放债权request列表
        List<RequestTransferDTO> transferList = new ArrayList<RequestTransferDTO>(creditDetailList.size());
        for (CreditDetailDto creditDetail : creditDetailList) {
            RequestTransferDTO transferDto = new RequestTransferDTO();
            transferDto.setCreditId(creditDetail.getCreditCode());// 债权协议编号
            transferDto.setTransferId(creditDetail.getTransferId());// 债权转让编号
            transferDto.setBackValue(creditDetail.getThisCreditorValue());// 本次释放债权价值
            transferDto.setContractNo(creditDetail.getCreditCode());
//            transferDto.setContractNo();
//            transferDto.setEachRepaymentValue(creditDetail.getThisRepaySum());// 本次释放对应月还金额
            transferDto.setIsWhole(creditDetail.getIsWhole());// 是否全部释放
            transferDto.setDeliveryDate(creditDetail.getRedeemDate());// 交割日期
            transferDto.setRepaymentAffiliation("0");//夸张单日月还归还我司
            transferList.add(transferDto);
        }
        req.setTransferList(transferList);
        InteractEnsureDto ensureDto = new InteractEnsureDto();
        ensureDto.setDealCode(redeemParamDto.getDealCode());
        Response4023DTO responseMsg = interactClient.sendReqToCore(
                (String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_CREDIT_REDEEM).get(
                        CimsIrtUrlConstant.IRT_URL), req, new TypeReference<ResponseMsg<Response4023DTO>>() {},
                ensureDto);
        if (responseMsg != null){
        	RedeemResultDto rdto = RedeemResultDto.successRedeemResultDto();
        	rdto.setCreditList(responseMsg.getCreditList());
        	rdto.setFrontTransNo(responseMsg.getFrontTransNo()); //合作机构交易流水号
        	rdto.setCoreTransNo(responseMsg.getCoreTransNo());  //核心交易流水号
        	rdto.setBusiCode(responseMsg.getBusiCode());  //业务编码
        	rdto.setInterfaceNo(responseMsg.getInterfaceNo());  //接口编码
        	rdto.setRetCode(responseMsg.getRetCode());   //返回码        0000：成功  0001：失败  9999:日终处理中
        	rdto.setRetTime(responseMsg.getRetTime());   //返回时间
        	rdto.setRetMsg(responseMsg.getRetMsg());     //返回信息
        	return rdto;
        }
        return null;
    }

    /**
     * 
     * @Title queryCreditRightBatch
     * @Description 合作机构申请债权批次信息查询
     * @param quotaRetrunDTOList
     * @return Response4025DTO
     * @author lixinyao
     * @date 2015-1-22-下午4:39:08
     * @update
     * @throws
     */
    public QuotaApplyResultDto getQuotaApplyResult(QuotaApplyParamDto paramDto) {
        Request4025DTO req = new Request4025DTO();
        req.setApplyId(paramDto.getQuotaDto().getQuotaCode());
        req.setTotalRows(paramDto.getTotalRows());
        req.setPageIndex(paramDto.getCurPage());
        req.setPageSize(paramDto.getPageSize());
        req.setInterfaceNo((String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_QUOTAAPPLY_CREDIT_RESULT)
                .get(CimsIrtUrlConstant.IRT_CODE));
        req.setBusiCode((String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_QUOTAAPPLY_CREDIT_RESULT)
                .get(CimsIrtUrlConstant.IRT_BUSICODE));

        InteractEnsureDto ensureDto = new InteractEnsureDto();
        ensureDto.setDealCode(paramDto.getDealCode());
        Response4025DTO responseMsg = interactClient.sendReqToCore(
                (String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_QUOTAAPPLY_CREDIT_RESULT).get(
                        CimsIrtUrlConstant.IRT_URL), req, new TypeReference<ResponseMsg<Response4025DTO>>() {},
                ensureDto);
        QuotaApplyResultDto quotaApplyResultDto = null;
        if (responseMsg != null && responseMsg.getRetCode().equals("0000")) {
            // 返回结果转换
            List<QuotaCreditRightDto> quotaCreditRightDtoList = new ArrayList<QuotaCreditRightDto>();
            List<CustInfoDto> quotaCustInfoDtoList = new ArrayList<CustInfoDto>();
            for (ResponseCreditsDTO responseCreditsDTO : responseMsg.getCreditList()) {
                // 债权信息部分
                QuotaCreditRightDto quotaCreditRightDto = new QuotaCreditRightDto();
                quotaCreditRightDto.setQuotaCode(paramDto.getQuotaDto().getQuotaCode());// 额度编号
                quotaCreditRightDto.setCreditCode(responseCreditsDTO.getCreditId());// 债权协议编号
                quotaCreditRightDto.setTransferId(responseCreditsDTO.getTransferId());// 转让编号
                quotaCreditRightDto.setBatchId(responseCreditsDTO.getBatchId()); // 批次号
                quotaCreditRightDto.setInitialCreditorValue(responseCreditsDTO.getInitCreditValue());// 初始债权价值
                quotaCreditRightDto.setPlanCreditorRield(responseCreditsDTO.getYearInterest());// 预计年化收益
                quotaCreditRightDto.setThisMakeCreditorValue(responseCreditsDTO.getTransTodayNowValue());// 当前转让债权价值
                quotaCreditRightDto.setThisCreditorValue(responseCreditsDTO.getTodayNowValue()); // 当前债权价值
                quotaCreditRightDto.setThisRepaySum(responseCreditsDTO.getTransEachRepaymentValue());// 每期还款金额
                quotaCreditRightDto.setBillDate(responseCreditsDTO.getBillDate());// 账单日

                quotaCreditRightDto.setContractSum(responseCreditsDTO.getContractValue());// 合同金额
                quotaCreditRightDto.setLoanSum(responseCreditsDTO.getLoanValue());// 放款金额
                quotaCreditRightDto.setBorrowerUse(responseCreditsDTO.getLoanUse());// 借款用途
                quotaCreditRightDto.setInitialLoanDate(responseCreditsDTO.getInitialDate()); // 初始放款日期
                quotaCreditRightDto.setRepayStartDate(responseCreditsDTO.getStartRepaymentDate());// 还款起始日期
                quotaCreditRightDto.setRepayPeriod(responseCreditsDTO.getRepaymentMonth());// 还款期数
                quotaCreditRightDto.setLoanUserId(responseCreditsDTO.getLoanUserId());// 贷款人编号
                quotaCreditRightDto.setLoanProductCode(responseCreditsDTO.getLoanProductCode());// 贷款产品代码
                quotaCreditRightDto.setLoanProductName(responseCreditsDTO.getLoanProductName());// 贷款产品名称
                quotaCreditRightDto.setLoanMonthlyinterest(responseCreditsDTO.getLoanMonthlyInterest());// 贷款月利率
                if (null != responseCreditsDTO.getLastRepaymentValue()){
                    quotaCreditRightDto.setResidueRepayPeriod(responseCreditsDTO.getLastRepaymentValue().longValue());// 剩余还款期数
                }
                quotaCreditRightDto.setRepayType(responseCreditsDTO.getRepaymenttype());//还款方式
                quotaCreditRightDto.setProductType(this.productTypeMap(responseCreditsDTO.getLoanType()));//合同类型转产品类型
                quotaCreditRightDto.setTotalRepaymentValue(responseCreditsDTO.getTotalRepaymentValue());//每期月还总金额
                quotaCreditRightDtoList.add(quotaCreditRightDto);
                // 客户信息部分
                CustInfoDto custInfoDto = new CustInfoDto();
                custInfoDto.setQuotaCode(paramDto.getQuotaDto().getQuotaCode());
                custInfoDto.setFromCode(responseCreditsDTO.getTransferId());
                custInfoDto.setCustCode(responseCreditsDTO.getCustCode());
                custInfoDto.setFromType(CimsConstant.QUOTATYPE_CR);
                custInfoDto.setCustName(responseCreditsDTO.getCustName());
                try {
                    custInfoDto.setBirthDate(InteractUtil.convert2Date(responseCreditsDTO.getBirthDate()));
                    custInfoDto.setCardValidDate(InteractUtil.convert2Date(responseCreditsDTO.getCardValidDate()));
                }
                catch (Exception e) {
                    throw new InteractException(CimsExceptionConstant.INTERACT_SERVICE_FAIL);
                }

                custInfoDto.setSex(responseCreditsDTO.getSex());
                custInfoDto.setCardType(responseCreditsDTO.getCardType());
                custInfoDto.setCardId(responseCreditsDTO.getCardId());
                custInfoDto.setDiploma(responseCreditsDTO.getDiploma());
                custInfoDto.setDuty(responseCreditsDTO.getDuty());
                custInfoDto.setIsHasHouse(responseCreditsDTO.getIsHasHouse());
                custInfoDto.setMarryStatus(responseCreditsDTO.getMarryStatus());
                custInfoDto.setIsHasChild(responseCreditsDTO.getIsHasChild());
                custInfoDto.setCompanyType(responseCreditsDTO.getCompanyType());
                custInfoDto.setHouseholdType(responseCreditsDTO.getHouseholdType());

                custInfoDto.setPhone(responseCreditsDTO.getPhone());
                custInfoDto.setEducation(responseCreditsDTO.getEducation());
                custInfoDto.setCustCrtTime(responseCreditsDTO.getCustCrtTime());

                quotaCustInfoDtoList.add(custInfoDto);
            }
            quotaApplyResultDto = QuotaApplyResultDto.successQuotaApplyResultDto();
        	quotaApplyResultDto.setTotalRows(responseMsg.getTotalRows());
            quotaApplyResultDto.setCrList(quotaCreditRightDtoList);
            quotaApplyResultDto.setCustInfoList(quotaCustInfoDtoList);
        } else {
            quotaApplyResultDto = new QuotaApplyResultDto();
        }
        return quotaApplyResultDto;

    }
    
  //接口合同类型与产品类型对应关系
  	private String productTypeMap(String loanType){
  		
  		if(loanType.equals(CimsConstant.CORE_PRODUCT_TYPE_CREDIT)){
  			return CimsConstant.PRODUCT_TYPE_CREDIT;
  		}else if(loanType.equals(CimsConstant.CORE_PRODUCT_TYPE_HOUSE)){
  			return CimsConstant.PRODUCT_TYPE_HOUSE;
  		}else if(loanType.equals(CimsConstant.CORE_PRODUCT_TYPE_CAR_YJ)||loanType.equals(CimsConstant.CORE_PRODUCT_TYPE_CAR_GPS)){
  			return CimsConstant.PRODUCT_TYPE_CAR;
  		}else{
  			return CimsConstant.PRODUCT_TYPE_NOT_EXIST;
  		}
  		
  	}

    public BatchCreditQueryResultDto getCreditDetail(BatchCreditQueryDto batchCreditQueryDto) {
        Request4026DTO req = new Request4026DTO();
        List<RequestTranferListDTO> list = new ArrayList<RequestTranferListDTO>();
        for (BatchCreditTranferListDTO batchCreditTranferListDTO : batchCreditQueryDto.getList()) {
            RequestTranferListDTO requestTranferListDTO = new RequestTranferListDTO();
            requestTranferListDTO.setTransferId(batchCreditTranferListDTO.getTransferId());
            requestTranferListDTO.setType(batchCreditTranferListDTO.getType());
            list.add(requestTranferListDTO);
        }
        req.setTransferList(list);
        req.setInterfaceNo((String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_CREDIT_SINGLE_QUERY).get(
                CimsIrtUrlConstant.IRT_CODE));
        req.setBusiCode((String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_CREDIT_SINGLE_QUERY).get(
                CimsIrtUrlConstant.IRT_BUSICODE));

        InteractEnsureDto ensureDto = new InteractEnsureDto();
        ensureDto.setDealCode(batchCreditQueryDto.getDealCode());
        Response4026DTO responseMsg = interactClient.sendReqToCore(
                (String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_CREDIT_SINGLE_QUERY).get(
                        CimsIrtUrlConstant.IRT_URL), req, new TypeReference<ResponseMsg<Response4026DTO>>() {},
                ensureDto);
        BatchCreditQueryResultDto batchCreditQueryResultDto = BatchCreditQueryResultDto
                .successSingleCreditQueryResultDto();
        if (responseMsg != null) {
            List<?> transferList = responseMsg.getTransferList();
            List<?> creditList = responseMsg.getCreditList();
            if (transferList != null || creditList != null) {
                // 返回结果转换
                // 债权信息部分
                if (transferList != null && !transferList.isEmpty()) {
                    List<CreditDetailDto> localTransferList = new ArrayList<CreditDetailDto>();
                    for (com.jy.modules.cims.data.interact.core.credit.response.ResponseTranserListDTO rtdto : responseMsg
                            .getTransferList()) {
                        if (rtdto.getCreditId() != null && !"null".equals(rtdto.getCreditId())) {
                            CreditDetailDto creditDetailDto = new CreditDetailDto();
                            creditDetailDto.setCreditCode(rtdto.getCreditId());// 债权协议编号
                            creditDetailDto.setCoreState(rtdto.getState());// 核心债权状态
                            creditDetailDto.setTransferId(rtdto.getTransferId());// 转让编号
                            // creditDetailDto.setBatchId(responseMsg.getBatchId());
                            // // 批次号
                            creditDetailDto.setInitialCreditorValue(rtdto.getInitCreditValue());// 初始债权价值
                            creditDetailDto.setPlanCreditorRield(rtdto.getYearInterest());// 预计年化收益
                            // creditDetailDto.setThisMakeCreditorValue(rtdto.getTransTodayNowValue());//
                            // 当前转让债权价值
                            creditDetailDto.setThisCreditorValue(rtdto.getTodayNowValue()); // 当前债权价值
                            creditDetailDto.setTodayStartValue(rtdto.getTodayStartValue());// 本日期初债权价值
                            creditDetailDto.setThisRepaySum(rtdto.getEachRepaymentValue());// 每期还款金额
                            creditDetailDto.setBillDate(rtdto.getBillDate());// 账单日

                            creditDetailDto.setContractSum(rtdto.getContractValue());// 合同金额
                            creditDetailDto.setLoanSum(rtdto.getLoanValue());// 放款金额
                            creditDetailDto.setBorrowerUse(rtdto.getLoanUse());// 借款用途
                            creditDetailDto.setInitialLoanDate(rtdto.getInitialDate()); // 初始放款日期
                            creditDetailDto.setRepayStartDate(rtdto.getStartRepaymentDate());// 还款起始日期
                            creditDetailDto.setRepayPeriod(rtdto.getRepaymentMonth());// 还款期数
                            creditDetailDto.setResidueRepayPeriod(rtdto.getRepaymentMonth());
                            creditDetailDto.setLoanUserId(rtdto.getLoanUserId());// 贷款人编号
                            creditDetailDto.setLoanProductCode(rtdto.getLoanProductCode());// 贷款产品代码
                            creditDetailDto.setLoanProductName(rtdto.getLoanProductName());// 贷款产品名称
                            creditDetailDto.setLoanMonthlyinterest(rtdto.getLoanMonthlyInterest());// 贷款月利率

                            creditDetailDto.setBorrowerName(rtdto.getCustName());
                            creditDetailDto.setBorrowerIdNumber(rtdto.getCardId());
                            creditDetailDto.setBizDate(rtdto.getBizDate());//当前会计日期
                            creditDetailDto.setTotalRepaymentValue(rtdto.getTotalRepaymentValue());//每期总月还金额
                            if (null != rtdto.getLastRepaymentValue())
                                creditDetailDto.setResidueRepayPeriod(rtdto.getLastRepaymentValue().longValue());
                            localTransferList.add(creditDetailDto);
                        }
                    }
                    batchCreditQueryResultDto.setTransferList(localTransferList);
                }
                if (creditList != null && !creditList.isEmpty()) {
                    List<CreditDetailDto> localCreditList = new ArrayList<CreditDetailDto>();
                    for (com.jy.modules.cims.data.interact.core.credit.response.ResponseTranserListDTO rtdto : responseMsg
                            .getCreditList()) {
                        if (rtdto.getCreditId() != null && !"null".equals(rtdto.getCreditId())) {
                            CreditDetailDto creditDetailDto = new CreditDetailDto();
                            creditDetailDto.setCreditCode(rtdto.getCreditId());// 债权协议编号
                            creditDetailDto.setCoreState(rtdto.getState());// 核心债权状态
                            creditDetailDto.setTransferId(rtdto.getCreditId());// 转让编号，合作机构放款，转让编号==合同号
                            // creditDetailDto.setBatchId(responseMsg.getBatchId());
                            // // 批次号
                            creditDetailDto.setInitialCreditorValue(rtdto.getInitCreditValue());// 初始债权价值
                            creditDetailDto.setPlanCreditorRield(rtdto.getYearInterest());// 预计年化收益
                            creditDetailDto.setThisMakeCreditorValue(rtdto.getTransTodayNowValue());// 当前转让债权价值
                            creditDetailDto.setThisCreditorValue(rtdto.getTransTodayNowValue()); // 当前债权价值
                            creditDetailDto.setTodayStartValue(rtdto.getTodayStartValue());// 本日期初债权价值
                            creditDetailDto.setThisRepaySum(rtdto.getEachRepaymentValue());// 每期还款金额
                            creditDetailDto.setBillDate(rtdto.getBillDate());// 账单日

                            creditDetailDto.setContractSum(rtdto.getContractValue());// 合同金额
                            creditDetailDto.setLoanSum(rtdto.getLoanValue());// 放款金额
                            creditDetailDto.setBorrowerUse(rtdto.getLoanUse());// 借款用途
                            creditDetailDto.setInitialLoanDate(rtdto.getInitialDate()); // 初始放款日期
                            creditDetailDto.setRepayStartDate(rtdto.getStartRepaymentDate());// 还款起始日期
                            creditDetailDto.setRepayPeriod(rtdto.getRepaymentMonth());// 还款期数
                            creditDetailDto.setResidueRepayPeriod(rtdto.getRepaymentMonth());
                            creditDetailDto.setLoanUserId(rtdto.getLoanUserId());// 贷款人编号
                            creditDetailDto.setLoanProductCode(rtdto.getLoanProductCode());// 贷款产品代码
                            creditDetailDto.setLoanProductName(rtdto.getLoanProductName());// 贷款产品名称
                            creditDetailDto.setLoanMonthlyinterest(rtdto.getLoanMonthlyInterest());// 贷款月利率

                            creditDetailDto.setBorrowerName(rtdto.getCustName());
                            creditDetailDto.setBorrowerIdNumber(rtdto.getCardId());
                            
                            creditDetailDto.setBizDate(rtdto.getBizDate());//当前会计日期
                            creditDetailDto.setTotalRepaymentValue(rtdto.getTotalRepaymentValue());//每期总月还金额
                            if (null != rtdto.getLastRepaymentValue())
                                creditDetailDto.setResidueRepayPeriod(rtdto.getLastRepaymentValue().longValue());
                            localCreditList.add(creditDetailDto);
                        }
                    }
                    batchCreditQueryResultDto.setCreditList(localCreditList);
                }
                return batchCreditQueryResultDto;
            }
        }
        return null;
    }

    /**
     * 根据合同号获取还款计划
     * 
     * @param contractNo
     * @return
     */
    public CreditRepayPlanQueryResultDto getCreditRepayPlan(CreditRepayPlanQueryDto queryDto) {

        Request4016DTO req = new Request4016DTO();
        req.setContractNo(queryDto.getContractNo());
        req.setInterfaceNo((String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_CREDIT_REPAYPLAN_QUERY)
                .get(CimsIrtUrlConstant.IRT_CODE));
        req.setBusiCode((String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_CREDIT_REPAYPLAN_QUERY).get(
                CimsIrtUrlConstant.IRT_BUSICODE));

        InteractEnsureDto ensureDto = new InteractEnsureDto();
        ensureDto.setDealCode(queryDto.getDealCode());
        Response4016DTO responseMsg = interactClient.sendReqToCore(
                (String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_CREDIT_REPAYPLAN_QUERY).get(
                        CimsIrtUrlConstant.IRT_URL), req, new TypeReference<ResponseMsg<Response4016DTO>>() {},
                ensureDto);

        CreditRepayPlanQueryResultDto creditRepayPlanQueryResultDto = null;
        if (responseMsg != null) {
            creditRepayPlanQueryResultDto = new CreditRepayPlanQueryResultDto();
            creditRepayPlanQueryResultDto.setContractNo(responseMsg.getContractNo());
            creditRepayPlanQueryResultDto.setChangeList(responseMsg.getChangeList());
            creditRepayPlanQueryResultDto.setPlantDataList(responseMsg.getPlantDataList());
            creditRepayPlanQueryResultDto.setBillDate(responseMsg.getBillDate());
        }

        return creditRepayPlanQueryResultDto;

    }

    public List<CreditValueCalculateResultDto> getCreditValue(CreditValueCalculateDto creditValueCalculateDto) {
        Request4028DTO req = new Request4028DTO();
        req.setInterfaceNo((String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_CREDIT_VALUE_QUERY).get(
                CimsIrtUrlConstant.IRT_CODE));
        req.setBusiCode((String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_CREDIT_VALUE_QUERY).get(
                CimsIrtUrlConstant.IRT_BUSICODE));
        List<RequestCreditValueDTO> queryList = new ArrayList<RequestCreditValueDTO>(creditValueCalculateDto
                .getBatchIdList().size());
        for (CreditValueCalculateDto.CreditValueCalculateBatch dto : creditValueCalculateDto.getBatchIdList()) {
            RequestCreditValueDTO requestCreditValueDTO = new RequestCreditValueDTO();
            requestCreditValueDTO.setTransferId(dto.getTransferId());
            requestCreditValueDTO.setCreditId(dto.getCreidtId());
            requestCreditValueDTO.setCreditDate(dto.getCreditDate());
            requestCreditValueDTO.setEachRepaymentValue(dto.getEachRepaymentValue());
            queryList.add(requestCreditValueDTO);
        }
        req.setBatchIdList(queryList);
        InteractEnsureDto ensureDto = new InteractEnsureDto();
        ensureDto.setDealCode(creditValueCalculateDto.getDealCode());
        Response4028DTO responseMsg = interactClient.sendReqToCore(
                (String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_CREDIT_VALUE_QUERY).get(
                        CimsIrtUrlConstant.IRT_URL), req, new TypeReference<ResponseMsg<Response4028DTO>>() {},
                ensureDto);
        if (responseMsg != null && responseMsg.getBatchIdList() != null) {
            List<CreditValueCalculateResultDto> resultList = new ArrayList<CreditValueCalculateResultDto>();
            for (ResponseCreditValueDTO responseCreditValueDTO : responseMsg.getBatchIdList()) {
                CreditValueCalculateResultDto dto = new CreditValueCalculateResultDto();
                dto.setCreditDate(responseCreditValueDTO.getCreditDate());
                dto.setTransferId(responseCreditValueDTO.getTransferId());
                dto.setEachRepaymentValue(responseCreditValueDTO.getEachRepaymentValue());
                dto.setCreditValue(responseCreditValueDTO.getCreditValue());
                resultList.add(dto);
            }
            return resultList;
        }
        return null;
    }

    /**
     * 查询公共信息
     * 
     * @title: getPublicInfo
     * @author: zhaox
     * @description:
     * @date 2015-5-20 下午2:11:41
     * @param publicInfoQueryDto
     * @return
     * @throws
     */
    public PublicInfoQueryResult getPublicInfo(PublicInfoQueryDto publicInfoQueryDto) {
        Request4011DTO req = new Request4011DTO();
        req.setInterfaceNo((String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_PUBLIC_INFO_QUERY).get(
                CimsIrtUrlConstant.IRT_CODE));
        req.setBusiCode((String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_PUBLIC_INFO_QUERY).get(
                CimsIrtUrlConstant.IRT_BUSICODE));
        req.setContractNo(publicInfoQueryDto.getContractNo());
        InteractEnsureDto ensureDto = new InteractEnsureDto();
        ensureDto.setDealCode(publicInfoQueryDto.getDealCode());
        Response4011DTO responseMsg = interactClient.sendReqToCore(
                (String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_PUBLIC_INFO_QUERY).get(
                        CimsIrtUrlConstant.IRT_URL), req, new TypeReference<ResponseMsg<Response4011DTO>>() {},
                ensureDto);
        if (responseMsg != null) {
            PublicInfoQueryResult publicInfoQueryResult = new PublicInfoQueryResult();
            publicInfoQueryResult.setAuditAmount(responseMsg.getQuiryAmount());
            publicInfoQueryResult.setContractNo(responseMsg.getContractNo());
            publicInfoQueryResult.setCurLoanPeriod(responseMsg.getCurLoanPeriod());
            publicInfoQueryResult.setCurNorBase(responseMsg.getCurNorBase());
            publicInfoQueryResult.setCurNorInst(responseMsg.getCurNorInst());
            publicInfoQueryResult.setCurRepayMoney(responseMsg.getCurRepayMoney());
            publicInfoQueryResult.setDefaultInst(responseMsg.getDefaultInst());
            publicInfoQueryResult.setEndDate(responseMsg.getEndDate());
            publicInfoQueryResult.setFundDate(responseMsg.getFundDate());
            publicInfoQueryResult.setIsStopInst(responseMsg.getIsStopInst());
            publicInfoQueryResult.setLoanAcctName(responseMsg.getLoanAcctName());
            publicInfoQueryResult.setLoanAcctNo(responseMsg.getLoanAcctNo());
            publicInfoQueryResult.setLoanBalance(responseMsg.getLoanBalance());
            publicInfoQueryResult.setLoanBankCode(responseMsg.getLoanBankCode());
            publicInfoQueryResult.setLoanStatus(responseMsg.getLoanStatus());
            publicInfoQueryResult.setManageAmount(responseMsg.getManageAmount());
            publicInfoQueryResult.setMonthRate(responseMsg.getMonthRate());
            publicInfoQueryResult.setNorDebtAmount(responseMsg.getNorDebtAmount());
            publicInfoQueryResult.setOverdueBase(responseMsg.getOverdueBase());
            publicInfoQueryResult.setOverdueDebtAmount(responseMsg.getOverdueDebtAmount());
            publicInfoQueryResult.setOverdueInst(responseMsg.getOverdueInst());
            publicInfoQueryResult.setPayoffDate(responseMsg.getPayoffDate());
            publicInfoQueryResult.setPayoffStatus(responseMsg.getPayoffStatus());
            publicInfoQueryResult.setPenaltyInst(responseMsg.getPenaltyInst());
            publicInfoQueryResult.setQuiryAmount(responseMsg.getQuiryAmount());
            publicInfoQueryResult.setRemainNorBase(responseMsg.getRemainNorBase());
            publicInfoQueryResult.setRemainNorInst(responseMsg.getRemainNorInst());
            publicInfoQueryResult.setRepayDay(responseMsg.getRepayDay());
            publicInfoQueryResult.setSuspendAmount(responseMsg.getSuspendAmount());
            publicInfoQueryResult.setTotalDebtAmount(responseMsg.getTotalDebtAmount());
            publicInfoQueryResult.setTotalRepayAmount(responseMsg.getTotalRepayAmount());
            publicInfoQueryResult.setTotalTerm(responseMsg.getTotalTerm());
            return publicInfoQueryResult;
        }
        return null;
    }
    
    public Response4029DTO sendSRCreditsToCore(Request4029DTO request) {
    	Request4029DTO req = request;
        req.setInterfaceNo((String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_SEND_SRCREDIT_TO_CORE).get(
                CimsIrtUrlConstant.IRT_CODE));
        req.setBusiCode((String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_SEND_SRCREDIT_TO_CORE).get(
                CimsIrtUrlConstant.IRT_BUSICODE));
        InteractEnsureDto ensureDto = new InteractEnsureDto();
        Response4029DTO responseMsg = interactClient.sendReqToCore(
                (String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_SEND_SRCREDIT_TO_CORE).get(
                        CimsIrtUrlConstant.IRT_URL), req, new TypeReference<ResponseMsg<Response4029DTO>>() {},
                ensureDto);
        if (responseMsg != null) {
            return responseMsg;
        }
        return null;
    }
    
    public Response4036DTO cancelSRCreditsToCore(Request4036DTO request) {
    	Request4036DTO req = request;
        req.setInterfaceNo((String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_CANCEL_SRCREDIT_TO_CORE).get(
                CimsIrtUrlConstant.IRT_CODE));
        req.setBusiCode((String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_CANCEL_SRCREDIT_TO_CORE).get(
                CimsIrtUrlConstant.IRT_BUSICODE));
        InteractEnsureDto ensureDto = new InteractEnsureDto();
        Response4036DTO responseMsg = interactClient.sendReqToCore(
                (String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_CANCEL_SRCREDIT_TO_CORE).get(
                        CimsIrtUrlConstant.IRT_URL), req, new TypeReference<ResponseMsg<Response4036DTO>>() {},
                ensureDto);
        if (responseMsg != null) {
            return responseMsg;
        }
        return null;
    }
    
    /**
	 * 查询结算信息
	 * 
	 * @author
	 * @description:
	 * @return
	 * @throws
	 */
	public SettleResultDto querySettleResultRepayment(SettleResult settleResult) throws Exception {
		Request4035DTO req = new Request4035DTO();
		
		req.setApplyCode(settleResult.getApplyCode());
		req.setApplyType(settleResult.getApplyType());
		req.setInterfaceNo((String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_SETTLE_RESULT_QUERY).get(
				CimsIrtUrlConstant.IRT_CODE));
		req.setBusiCode((String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_SETTLE_RESULT_QUERY).get(
				CimsIrtUrlConstant.IRT_BUSICODE));
		
		InteractEnsureDto ensureDto = new InteractEnsureDto();
		ensureDto.setDealCode(settleResult.getDealCode());
		Response4035DTO response = null;
		response = interactClient.sendReqToCore(
				(String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_SETTLE_RESULT_QUERY).get(CimsIrtUrlConstant.IRT_URL), req,
				new TypeReference<ResponseMsg<Response4035DTO>>() {
				}, ensureDto);
		if (response != null) {
			SettleResultDto settleResultDto = new SettleResultDto();
			settleResultDto.setApplyCode(response.getApplyCode());
			settleResultDto.setApplyType(response.getApplyType());
			settleResultDto.setState(response.getState());
			return settleResultDto;
		}
		
		return null;
	}
	
	 /**
     * 债权受让赎回接口4038
     * @Description 
     * @return
     * @throws Exception   
     * RedeemResultDto  
     * @throws
     * @author zhangmi
     * @date 2016-2-1
     */
    public RedeemResultDto sendSrCreditorBatchRedeemToCore(RedeemParamDto redeemParamDto) throws Exception{
    	String busiNoForInteract = iInteractAssist.getInteractNo();
    	redeemParamDto.setFrontTransNo(busiNoForInteract);
    	Request4038DTO req = new Request4038DTO();
    	List<TCMmCreditDetailDTO> creditDetailDTOList = redeemParamDto.gettCMmCreditDetailDTOList();
    	
    	req.setBatchId(redeemParamDto.getDealCode());
    	req.setCCode(redeemParamDto.getCCode());
    	req.setFrontTransNo(busiNoForInteract);
    	req.setInterfaceNo((String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_SRCREDIT_TRANSFER_REDEEM_TO_CORE).get(CimsIrtUrlConstant.IRT_CODE));  //接口编码
        req.setBusiCode((String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_SRCREDIT_TRANSFER_REDEEM_TO_CORE).get(CimsIrtUrlConstant.IRT_BUSICODE)); //业务编码
        List<RequestCreditRedemptionDTO> transferList = new ArrayList<RequestCreditRedemptionDTO>();
    	for(TCMmCreditDetailDTO creditDetailDTO: creditDetailDTOList ){
    		RequestCreditRedemptionDTO reqDto = new RequestCreditRedemptionDTO();
    		reqDto.setContractNo(creditDetailDTO.getContractCode());
    		reqDto.setCreditId(creditDetailDTO.getTransferId());
    		reqDto.setDeliveryDate(creditDetailDTO.getRedeemDate());
    		transferList.add(reqDto);
    	}
    	req.setTransferList(transferList);
    	
    	InteractEnsureDto ensureDto = new InteractEnsureDto();
        ensureDto.setDealCode(redeemParamDto.getDealCode());
        Response4038DTO responseMsg = interactClient.sendReqToCore(
                (String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_SRCREDIT_TRANSFER_REDEEM_TO_CORE).get(
                        CimsIrtUrlConstant.IRT_URL), req, new TypeReference<ResponseMsg<Response4038DTO>>() {},
                ensureDto);
        
        if (responseMsg != null){
        	RedeemResultDto rdto = RedeemResultDto.successRedeemResultDto();
        	rdto.setFrontTransNo(responseMsg.getFrontTransNo()); //合作机构交易流水号
        	rdto.setCoreTransNo(responseMsg.getCoreTransNo());  //核心交易流水号
        	rdto.setBusiCode(responseMsg.getBusiCode());  //业务编码
        	rdto.setInterfaceNo(responseMsg.getInterfaceNo());  //接口编码
        	rdto.setRetCode(responseMsg.getRetCode());   //返回码        0000：成功  0001：失败  9999:日终处理中
        	rdto.setRetTime(responseMsg.getRetTime());   //返回时间
        	rdto.setRetMsg(responseMsg.getRetMsg());     //返回信息
        	rdto.setSrTransferList(responseMsg.getTransferList());
        	return rdto;
        }
    	return null;
    }

    /**
     * 
     * @Description 债权转让赎回结算
     * @param settleRedeenParamDto
     * @return
     * @throws Exception   
     * SettleRedeenResultDto  
     * @throws
     * @author zhangmi
     * @date 2016-4-11
     */
    public PublicSettleResultDto sendZrCreditRedeemSettle(PublicSettleParamDto publicSettleParamDto) throws Exception{
    	String busiNoForInteract = iInteractAssist.getInteractNo();
    	publicSettleParamDto.setFrontTransNo(busiNoForInteract);
    	Request4039DTO req = new Request4039DTO();
    	List<CreditRedeemSettleDto> listRedeemSettle = publicSettleParamDto.getListRedeemSettle();
    	
    	req.setApplyCode(publicSettleParamDto.getApplyCode());//结算编号
    	req.setApplyName(publicSettleParamDto.getApplyName());//申请人
    	req.setCCode(publicSettleParamDto.getCCode());
    	req.setFrontTransNo(busiNoForInteract);
    	req.setInterfaceNo((String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_ZRCREDIT_REDEEM_SETTLE_TO_CORE).get(CimsIrtUrlConstant.IRT_CODE));  //接口编码
        req.setBusiCode((String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_ZRCREDIT_REDEEM_SETTLE_TO_CORE).get(CimsIrtUrlConstant.IRT_BUSICODE)); //业务编码
        List<RequestRedeemDTO> redeemList = new ArrayList<RequestRedeemDTO>();
    	for(CreditRedeemSettleDto creditRedeemSettle: listRedeemSettle ){
    		RequestRedeemDTO reqDto = new RequestRedeemDTO();
    		reqDto.setTransferId(creditRedeemSettle.getTransferId()); //债权转让债权编号
    		reqDto.setRedeemValue(creditRedeemSettle.getRedeemValue()); //赎回债权价值
    		reqDto.setServiceCharge(creditRedeemSettle.getServiceCharge()); //服务费
    		reqDto.setGuaranteeFee(creditRedeemSettle.getGuaranteeFee());//担保费
    		reqDto.setCashDeposit(creditRedeemSettle.getCashDeposit()); //保证金
    		reqDto.setBatchId(publicSettleParamDto.getDealCode());//流水号
    		
    		redeemList.add(reqDto);
    	}
    	req.setCreditList(redeemList);
    	
    	InteractEnsureDto ensureDto = new InteractEnsureDto();
        ensureDto.setDealCode(publicSettleParamDto.getDealCode());//交易流水号
        Response4039DTO responseMsg = interactClient.sendReqToCore(
                (String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_ZRCREDIT_REDEEM_SETTLE_TO_CORE).get(
                        CimsIrtUrlConstant.IRT_URL), req, new TypeReference<ResponseMsg<Response4039DTO>>() {},
                ensureDto);
        if (responseMsg != null){
        	PublicSettleResultDto rltdto = PublicSettleResultDto.successPublicSettleResultDto();
        	rltdto.setApplyCode(responseMsg.getApplyCode());
        	rltdto.setFrontTransNo(responseMsg.getFrontTransNo()); //合作机构交易流水号
        	rltdto.setCoreTransNo(responseMsg.getCoreTransNo());  //核心交易流水号
        	rltdto.setBusiCode(responseMsg.getBusiCode());  //业务编码
        	rltdto.setInterfaceNo(responseMsg.getInterfaceNo());  //接口编码
        	rltdto.setRetCode(responseMsg.getRetCode());   //返回码        0000：成功  0001：失败  9999:日终处理中
        	rltdto.setRetTime(responseMsg.getRetTime());   //返回时间
        	rltdto.setRetMsg(responseMsg.getRetMsg());     //返回信息
        	return rltdto;
        }
    	return null;
    }
    
    /**
     * 
     * @Description    虚拟月还挂账
     * PublicSettleResultDto   
     * @throws
     * @author zhangmi
     * @date 2016-4-11
     */
    public PublicSettleResultDto sendVRMonthGz(PublicSettleParamDto publicSettleParamDto){
    	String busiNoForInteract = iInteractAssist.getInteractNo();
    	publicSettleParamDto.setFrontTransNo(busiNoForInteract);
    	Request4040DTO req = new Request4040DTO();
    	List<CreditVrMonthRepayDto> listVrMonthRepay = publicSettleParamDto.getListVrMonthRepay();
    	
    	req.setCCode(publicSettleParamDto.getCCode());
    	req.setFrontTransNo(busiNoForInteract);
    	req.setInterfaceNo((String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_CREDIT_VR_GZ_TO_CORE).get(CimsIrtUrlConstant.IRT_CODE));  //接口编码
        req.setBusiCode((String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_CREDIT_VR_GZ_TO_CORE).get(CimsIrtUrlConstant.IRT_BUSICODE)); //业务编码
        List<RequestCreditTransferVirtualRepayDTO> virtualRepayList = new ArrayList<RequestCreditTransferVirtualRepayDTO>();
        
        for (CreditVrMonthRepayDto creditVrMonthRepay : listVrMonthRepay) {
        	RequestCreditTransferVirtualRepayDTO sonTransferDto = new RequestCreditTransferVirtualRepayDTO();
        	sonTransferDto.setTransferId(creditVrMonthRepay.getTransferId());
        	sonTransferDto.setCurRepayDate(creditVrMonthRepay.getCurRepayDate());
        	sonTransferDto.setEachRepaymentPeriods(creditVrMonthRepay.getEachRepaymentPeriods());
        	sonTransferDto.setEachRepaymentValue(creditVrMonthRepay.getEachRepaymentValue());
        	virtualRepayList.add(sonTransferDto);
		}
        req.setVirtualRepayList(virtualRepayList);
        
        InteractEnsureDto ensureDto = new InteractEnsureDto();
        ensureDto.setDealCode(publicSettleParamDto.getDealCode());//交易流水号
        Response4040DTO responseMsg = interactClient.sendReqToCore(
                (String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_CREDIT_VR_GZ_TO_CORE).get(
                        CimsIrtUrlConstant.IRT_URL), req, new TypeReference<ResponseMsg<Response4040DTO>>() {},
                ensureDto);
        if (responseMsg != null){
        	PublicSettleResultDto rltdto = PublicSettleResultDto.successPublicSettleResultDto();
        	rltdto.setApplyCode(responseMsg.getApplyId());
        	rltdto.setFrontTransNo(responseMsg.getFrontTransNo()); //合作机构交易流水号
        	rltdto.setCoreTransNo(responseMsg.getCoreTransNo());  //核心交易流水号
        	rltdto.setBusiCode(responseMsg.getBusiCode());  //业务编码
        	rltdto.setInterfaceNo(responseMsg.getInterfaceNo());  //接口编码
        	rltdto.setRetCode(responseMsg.getRetCode());   //返回码        0000：成功  0001：失败  9999:日终处理中
        	rltdto.setRetTime(responseMsg.getRetTime());   //返回时间
        	rltdto.setRetMsg(responseMsg.getRetMsg());     //返回信息
        	return rltdto;
        }
    	return null;
    }
    /**
     * 
     * @Description 二次购买-接口
     * @param publicSettleParamDto
     * @return   
     * PublicSettleResultDto  
     * @throws
     * @author zhangmi
     * @date 2016-4-12
     */
    public PublicSettleResultDto sendTwoCreditBuy(PublicSettleParamDto publicSettleParamDto){
    	String busiNoForInteract = iInteractAssist.getInteractNo();
    	publicSettleParamDto.setFrontTransNo(busiNoForInteract);
    	Request4041DTO req = new Request4041DTO();
    	//List<CreditDetailDto> creditDetailList = publicSettleRedeenParamDto.getCreditDetailList();
    	//req.setBatchId(redeemParamDto.getDealCode());
    	List<CreditTwoBuyRepayDto> listTwoBuyRepay = publicSettleParamDto.getListTwoBuyRepay();
    	List<CreditTwoBuySettleDto> listTwoBuySettle = publicSettleParamDto.getListTwoBuySettle();
    	List<CreditTwoBuyMatchDto> listTwoBuyMatch = publicSettleParamDto.getListTwoBuyMatch();
    	
    	req.setApplyCode(publicSettleParamDto.getApplyCode());//结算编号
    	req.setApplyName(publicSettleParamDto.getApplyName());//申请人
    	req.setCCode(publicSettleParamDto.getCCode()); //合作机构
    	req.setFrontTransNo(busiNoForInteract);
    	req.setInterfaceNo((String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_CREDIT_TWO_BUY_TO_CORE).get(CimsIrtUrlConstant.IRT_CODE));  //接口编码
        req.setBusiCode((String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_CREDIT_TWO_BUY_TO_CORE).get(CimsIrtUrlConstant.IRT_BUSICODE)); //业务编码
        req.setBizType(publicSettleParamDto.getBizType());
        /**
         * 月还列表
         */
        List<RequestRepaymentDTO> repaymentList = new ArrayList<RequestRepaymentDTO>();
        RequestRepaymentDTO rpyDto = null;
        for (CreditTwoBuyRepayDto creditTwoBuyRepay : listTwoBuyRepay) {
        	rpyDto = new RequestRepaymentDTO();
        	rpyDto.setContractNo(creditTwoBuyRepay.getContractNo());
        	rpyDto.setCreditValue(creditTwoBuyRepay.getCreditValue());
        	rpyDto.setEachRepaymentDate(creditTwoBuyRepay.getEachRepaymentDate());
        	rpyDto.setEachRepaymentValue(creditTwoBuyRepay.getEachRepaymentValue());
        	rpyDto.setIsVirtualRepay(creditTwoBuyRepay.getIsVirtualRepay());
        	rpyDto.setTransferId(creditTwoBuyRepay.getTransferId());
        	rpyDto.setEachRepaymentPeriods(creditTwoBuyRepay.getEachRepaymentPeriods());
        	repaymentList.add(rpyDto);
		}
        req.setRepaymentList(repaymentList);
        
        /**
         * 提前结清列表
         */
        List<RequestSettleDTO> settleList = new ArrayList<RequestSettleDTO>();
        RequestSettleDTO rstDto = null;
        for (CreditTwoBuySettleDto creditTwoBuySettle : listTwoBuySettle) {
        	rstDto = new RequestSettleDTO();
        	rstDto.setContractNo(creditTwoBuySettle.getContractNo());
        	rstDto.setSettleValue(creditTwoBuySettle.getSettleValue());
        	rstDto.setTransferId(creditTwoBuySettle.getTransferId());
        	rstDto.setTotalSettleValue(creditTwoBuySettle.getTotalSettleValue());
        	settleList.add(rstDto);
		}
        req.setSettleList(settleList);
        
        /**
         * 二次购买债权列表
         */
        List<RequestMatchCreditDTO> matchList = new ArrayList<RequestMatchCreditDTO>();
        RequestMatchCreditDTO mthDto = null;
        for (CreditTwoBuyMatchDto creditTwoBuyMatchDto : listTwoBuyMatch) {
        	mthDto = new RequestMatchCreditDTO();
        	mthDto.setContractNo(creditTwoBuyMatchDto.getContractNo());
        	mthDto.setDeliveryDate(creditTwoBuyMatchDto.getDeliveryDate());
        	mthDto.setRepaymentAffiliation(publicSettleParamDto.getRepaymentAffiliation());
        	mthDto.setDeliveryValue(creditTwoBuyMatchDto.getDeliveryValue());
        	mthDto.setTransferId(creditTwoBuyMatchDto.getTransferId());
        	mthDto.setEachRepaymentValue(creditTwoBuyMatchDto.getEachRepaymentValue());
        	matchList.add(mthDto);
		}
        req.setMatchList(matchList);
        
        InteractEnsureDto ensureDto = new InteractEnsureDto();
        ensureDto.setDealCode(publicSettleParamDto.getDealCode());//交易流水号
        Response4041DTO responseMsg = interactClient.sendReqToCore(
                (String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_CREDIT_TWO_BUY_TO_CORE).get(
                        CimsIrtUrlConstant.IRT_URL), req, new TypeReference<ResponseMsg<Response4041DTO>>() {},
                ensureDto);
        if (responseMsg != null){
        	PublicSettleResultDto rltdto = PublicSettleResultDto.successPublicSettleResultDto();
        	rltdto.setListCreditTwoBuy(responseMsg.getResultList()); //二次购买债权列表
        	rltdto.setFrontTransNo(responseMsg.getFrontTransNo()); //合作机构交易流水号
        	rltdto.setCoreTransNo(responseMsg.getCoreTransNo());  //核心交易流水号
        	rltdto.setBusiCode(responseMsg.getBusiCode());  //业务编码
        	rltdto.setInterfaceNo(responseMsg.getInterfaceNo());  //接口编码
        	rltdto.setRetCode(responseMsg.getRetCode());   //返回码        0000：成功  0001：失败  9999:日终处理中
        	rltdto.setRetTime(responseMsg.getRetTime());   //返回时间
        	rltdto.setRetMsg(responseMsg.getRetMsg());     //返回信息
        	return rltdto;
        }
    	return null;
    }
    /**
     * 
     * @Description 月还现金结算
     * @param publicSettleParamDto
     * @return   
     * PublicSettleResultDto  
     * @throws
     * @author zhangmi
     * @date 2016-4-12
     */
    public PublicSettleResultDto sendMonthCashRepay(PublicSettleParamDto publicSettleParamDto){
    	String busiNoForInteract = iInteractAssist.getInteractNo();
    	publicSettleParamDto.setFrontTransNo(busiNoForInteract);
    	Request4042DTO req = new Request4042DTO();
    	
    	List<CreditVrMonthRepayDto> listMonthRepay = publicSettleParamDto.getListVrMonthRepay();
    	
    	req.setApplyCode(publicSettleParamDto.getApplyCode());//结算编号
    	req.setApplyName(publicSettleParamDto.getApplyName());//申请人
    	req.setCCode(publicSettleParamDto.getCCode()); //合作机构
    	req.setBizType(publicSettleParamDto.getBizType());//业务类型(2-债权转出 3-贷款转出)
    	req.setFrontTransNo(busiNoForInteract);//合作机构交易流水号
    	req.setInterfaceNo((String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_CREDIT_MONTHCASH_REPAY_TO_CORE).get(CimsIrtUrlConstant.IRT_CODE));  //接口编码
        req.setBusiCode((String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_CREDIT_MONTHCASH_REPAY_TO_CORE).get(CimsIrtUrlConstant.IRT_BUSICODE)); //业务编码
        List<RequestCashRepayDTO> creditList = new ArrayList<RequestCashRepayDTO>();
        RequestCashRepayDTO cashDto = null;
        for (CreditVrMonthRepayDto creditMonthRepay : listMonthRepay) {
        	cashDto = new RequestCashRepayDTO();
        	cashDto.setCashSum(creditMonthRepay.getCashSum());
        	cashDto.setContractNo(creditMonthRepay.getContractNo());
        	cashDto.setEachRepaymentDate(creditMonthRepay.getCurRepayDate());
        	cashDto.setEachRepaymentPeriods(creditMonthRepay.getEachRepaymentPeriods());
        	cashDto.setEachRepaymentValue(creditMonthRepay.getEachRepaymentValue());
        	cashDto.setIsVirtualRepay(creditMonthRepay.getIsVirtualRepay());
        	cashDto.setTransferId(creditMonthRepay.getTransferId());
        	if(creditMonthRepay.getCashSum().compareTo(BigDecimal.ZERO)==1){
        		creditList.add(cashDto);
        	}
		}
        req.setCreditList(creditList);
        if(req.getCreditList().size()>0){
        	InteractEnsureDto ensureDto = new InteractEnsureDto();
            ensureDto.setDealCode(publicSettleParamDto.getDealCode());//交易流水号
            Response4042DTO responseMsg = interactClient.sendReqToCore(
                    (String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_CREDIT_MONTHCASH_REPAY_TO_CORE).get(
                            CimsIrtUrlConstant.IRT_URL), req, new TypeReference<ResponseMsg<Response4042DTO>>() {},
                    ensureDto);
            if (responseMsg != null){
            	PublicSettleResultDto rltdto = PublicSettleResultDto.successPublicSettleResultDto();
            	rltdto.setApplyCode(responseMsg.getApplyCode());
            	rltdto.setFrontTransNo(responseMsg.getFrontTransNo()); //合作机构交易流水号
            	rltdto.setCoreTransNo(responseMsg.getCoreTransNo());  //核心交易流水号
            	rltdto.setBusiCode(responseMsg.getBusiCode());  //业务编码
            	rltdto.setInterfaceNo(responseMsg.getInterfaceNo());  //接口编码
            	rltdto.setRetCode(responseMsg.getRetCode());   //返回码        0000：成功  0001：失败  9999:日终处理中
            	rltdto.setRetTime(responseMsg.getRetTime());   //返回时间
            	rltdto.setRetMsg(responseMsg.getRetMsg());     //返回信息
            	return rltdto;
            }
        }
        
    	return null;
    }
    /**
     * 
     * @Description 结清债权现金结算
     * @param publicSettleParamDto
     * @return   
     * PublicSettleResultDto  
     * @throws
     * @author zhangmi
     * @date 2016-4-12
     */
    public PublicSettleResultDto sendCreditCashSettle(PublicSettleParamDto publicSettleParamDto){
    	String busiNoForInteract = iInteractAssist.getInteractNo();
    	publicSettleParamDto.setFrontTransNo(busiNoForInteract);
    	Request4043DTO req = new Request4043DTO();
    	List<CreditRedeemSettleDto> listCashSettle = publicSettleParamDto.getListRedeemSettle();
    	
    	req.setApplyId(publicSettleParamDto.getApplyCode());//结算编号
    	req.setApplyName(publicSettleParamDto.getApplyName());//申请人
    	req.setCCode(publicSettleParamDto.getCCode()); //合作机构
    	req.setFrontTransNo(busiNoForInteract);//合作机构交易流水号
    	req.setBizType(publicSettleParamDto.getBizType());//业务类型
    	req.setInterfaceNo((String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_CREDIT_CASH_SETTLE_TO_CORE).get(CimsIrtUrlConstant.IRT_CODE));  //接口编码
        req.setBusiCode((String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_CREDIT_CASH_SETTLE_TO_CORE).get(CimsIrtUrlConstant.IRT_BUSICODE)); //业务编码
        
        List<RequestCreditSettlementEarlyDTO> settleList = new ArrayList<RequestCreditSettlementEarlyDTO>();
        RequestCreditSettlementEarlyDTO cutDto = null;
        for (CreditRedeemSettleDto creditSettle : listCashSettle) {
        	cutDto = new RequestCreditSettlementEarlyDTO();
        	cutDto.setTransferId(creditSettle.getTransferId()); //债权转让编号
        	cutDto.setTotalSettleValue(creditSettle.getTotalSettleValue());//合作机构要求总结清价值
        	cutDto.setRedeemValue(creditSettle.getSettleCreditorValue()); //合作机构要求结清价值 
        	cutDto.setServiceCharge(creditSettle.getServiceCharge());//服务费（退费金额）
        	cutDto.setGuaranteeFee(creditSettle.getGuaranteeFee());//担保费（退费金额）
        	cutDto.setCashDeposit(creditSettle.getCashDeposit()); ////保证金（退费金额）
        	settleList.add(cutDto);
		}
        req.setSettleList(settleList);
        
        InteractEnsureDto ensureDto = new InteractEnsureDto();
        ensureDto.setDealCode(publicSettleParamDto.getDealCode());//交易流水号
        Response4043DTO responseMsg = interactClient.sendReqToCore(
                (String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_CREDIT_CASH_SETTLE_TO_CORE).get(
                        CimsIrtUrlConstant.IRT_URL), req, new TypeReference<ResponseMsg<Response4043DTO>>() {},
                ensureDto);
        if (responseMsg != null){
        	PublicSettleResultDto rltdto = PublicSettleResultDto.successPublicSettleResultDto();
        	rltdto.setApplyCode(responseMsg.getApplyId());
        	rltdto.setFrontTransNo(responseMsg.getFrontTransNo()); //合作机构交易流水号
        	rltdto.setCoreTransNo(responseMsg.getCoreTransNo());  //核心交易流水号
        	rltdto.setBusiCode(responseMsg.getBusiCode());  //业务编码
        	rltdto.setInterfaceNo(responseMsg.getInterfaceNo());  //接口编码
        	rltdto.setRetCode(responseMsg.getRetCode());   //返回码        0000：成功  0001：失败  9999:日终处理中
        	rltdto.setRetTime(responseMsg.getRetTime());   //返回时间
        	rltdto.setRetMsg(responseMsg.getRetMsg());     //返回信息
        	return rltdto;
        }
    	return null;
    }
    
    /**
     * 
     * @Description 发送结算申请
     * @param publicSettleParamDto
     * @return   
     * PublicSettleResultDto  
     * @throws
     * @author zhangmi
     * @date 2016-4-12
     */
    public PublicSettleResultDto sendSettleApply(PublicSettleParamDto publicSettleParamDto){
    	String busiNoForInteract = iInteractAssist.getInteractNo();
    	publicSettleParamDto.setFrontTransNo(busiNoForInteract);
    	Request4044DTO req = new Request4044DTO();
    	List<CreditDetailDto> listCreditDetal = publicSettleParamDto.getCreditDetailList();
    	req.setApplyId(publicSettleParamDto.getApplyCode());//结算编号
    	req.setApplyName(publicSettleParamDto.getApplyName());//申请人
    	req.setCCode(publicSettleParamDto.getCCode()); //合作机构
    	req.setFrontTransNo(busiNoForInteract);
    	req.setInterfaceNo((String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_CREDIT_SETTLE__APPLY_TO_CORE).get(CimsIrtUrlConstant.IRT_CODE));  //接口编码
        req.setBusiCode((String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_CREDIT_SETTLE__APPLY_TO_CORE).get(CimsIrtUrlConstant.IRT_BUSICODE)); //业务编码
        List<RequestCreditSettlementDTO> creditList = new ArrayList<RequestCreditSettlementDTO>();
        RequestCreditSettlementDTO rasDto = null;
        for (CreditDetailDto creditDetailDto : listCreditDetal) {
        	rasDto = new  RequestCreditSettlementDTO();
        	rasDto.setTransferId(creditDetailDto.getTransferId()); //转让编号
        	rasDto.setMakeCreditorValue(creditDetailDto.getMakeCreditorValue());//合作机构要求的交割价值
        	rasDto.setServiceCharge(creditDetailDto.getServiceCharge());//服务费
        	rasDto.setGuaranteeFee(creditDetailDto.getGuaranteeFee()); //担保费
        	rasDto.setCashDeposit(creditDetailDto.getCautionMoney()); //保证金
        	creditList.add(rasDto);
		}
        req.setCreditList(creditList);
        
        InteractEnsureDto ensureDto = new InteractEnsureDto();
        ensureDto.setDealCode(publicSettleParamDto.getDealCode());//交易流水号
        Response4044DTO responseMsg = interactClient.sendReqToCore(
                (String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_CREDIT_SETTLE__APPLY_TO_CORE).get(
                        CimsIrtUrlConstant.IRT_URL), req, new TypeReference<ResponseMsg<Response4044DTO>>() {},
                ensureDto);
        if (responseMsg != null){
        	PublicSettleResultDto rltdto = PublicSettleResultDto.successPublicSettleResultDto();
        	rltdto.setApplyCode(responseMsg.getApplyId());
        	rltdto.setFrontTransNo(responseMsg.getFrontTransNo()); //合作机构交易流水号
        	rltdto.setCoreTransNo(responseMsg.getCoreTransNo());  //核心交易流水号
        	rltdto.setBusiCode(responseMsg.getBusiCode());  //业务编码
        	rltdto.setInterfaceNo(responseMsg.getInterfaceNo());  //接口编码
        	rltdto.setRetCode(responseMsg.getRetCode());   //返回码        0000：成功  0001：失败  9999:日终处理中
        	rltdto.setRetTime(responseMsg.getRetTime());   //返回时间
        	rltdto.setRetMsg(responseMsg.getRetMsg());     //返回信息
        	return rltdto;
        }
    	return null;
    }
    
    /**
     * 
     * @Description 二次购买-撤销接口
     * @param publicSettleParamDto
     * @return   
     * PublicSettleResultDto  
     * @throws
     * @author zhoupeng
     * @date 2016-6-21
     */
    public PublicSettleResultDto sendTwoCreditBuyReturn(PublicSettleParamDto publicSettleParamDto){
    	String busiNoForInteract = iInteractAssist.getInteractNo();
    	publicSettleParamDto.setFrontTransNo(busiNoForInteract);
    	Request4046DTO req = new Request4046DTO();
    	
    	
    	req.setApplyCode(publicSettleParamDto.getApplyCode());//结算编号
    	req.setApplyName(publicSettleParamDto.getApplyName());//申请人
    	req.setFrontTransNo(busiNoForInteract);
    	req.setInterfaceNo((String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_CREDIT_TWO_BUY_TO_CORE_Return).get(CimsIrtUrlConstant.IRT_CODE));  //接口编码
        req.setBusiCode((String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_CREDIT_TWO_BUY_TO_CORE_Return).get(CimsIrtUrlConstant.IRT_BUSICODE)); //业务编码
     
        InteractEnsureDto ensureDto = new InteractEnsureDto();
        ensureDto.setDealCode(publicSettleParamDto.getDealCode());//交易流水号
        Response4046DTO responseMsg = interactClient.sendReqToCore(
                (String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_CREDIT_TWO_BUY_TO_CORE_Return).get(
                        CimsIrtUrlConstant.IRT_URL), req, new TypeReference<ResponseMsg<Response4046DTO>>() {},
                ensureDto);
        if (responseMsg != null){
        	PublicSettleResultDto rltdto = PublicSettleResultDto.successPublicSettleResultDto();
        	rltdto.setFrontTransNo(responseMsg.getFrontTransNo()); //合作机构交易流水号
        	rltdto.setCoreTransNo(responseMsg.getCoreTransNo());  //核心交易流水号
        	rltdto.setBusiCode(responseMsg.getBusiCode());  //业务编码
        	rltdto.setInterfaceNo(responseMsg.getInterfaceNo());  //接口编码
        	rltdto.setRetCode(responseMsg.getRetCode());   //返回码        0000：成功  0001：失败  9999:日终处理中
        	rltdto.setRetTime(responseMsg.getRetTime());   //返回时间
        	rltdto.setRetMsg(responseMsg.getRetMsg());     //返回信息
        	return rltdto;
        }
    	return null;
    }
    
    /**
     * 
     * @author zhangmi
     * @date  2017年2月22日
     * @param publicSettleParamDto
     * @return
     */
    public AutoPretendResultDto autoPretendCredit(AutoPretendParamDto autoPretendParamDto){
    	String busiNoForInteract = iInteractAssist.getInteractNo();
    	autoPretendParamDto.setFrontTransNo(busiNoForInteract);
    	Request4050DTO req = new Request4050DTO();
    	req.setPackageNo(autoPretendParamDto.getPackageNo());//
    	req.setApplyId(autoPretendParamDto.getQuotaCode());//额度号
    	req.setDeliveryDate(autoPretendParamDto.getDeliveryDate());//交割日
    	req.setDeliveryDateValue(autoPretendParamDto.getDeliveryDateValue());//交割价值
    	req.setFrontTransNo(busiNoForInteract);
    	req.setInterfaceNo((String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_CREDIT_TWO_BUY_TO_CORE_AUTOPRETEND).get(CimsIrtUrlConstant.IRT_CODE));  //接口编码
        req.setBusiCode((String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_CREDIT_TWO_BUY_TO_CORE_AUTOPRETEND).get(CimsIrtUrlConstant.IRT_BUSICODE)); //业务编码
        InteractEnsureDto ensureDto = new InteractEnsureDto();
        ensureDto.setDealCode(autoPretendParamDto.getDealCode());//交易流水号
        Response4050DTO responseMsg = interactClient.sendReqToCore(
                (String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_CREDIT_TWO_BUY_TO_CORE_AUTOPRETEND).get(
                        CimsIrtUrlConstant.IRT_URL), req, new TypeReference<ResponseMsg<Response4050DTO>>() {},
                ensureDto);
        if (responseMsg != null){
        	AutoPretendResultDto  rltdto = AutoPretendResultDto.successAutoPretendResultDto();
        	rltdto.setResultList(responseMsg.getResultList());//新匹配的债权
        	rltdto.setFrontTransNo(responseMsg.getFrontTransNo()); //合作机构交易流水号
        	rltdto.setCoreTransNo(responseMsg.getCoreTransNo());  //核心交易流水号
        	rltdto.setBusiCode(responseMsg.getBusiCode());  //业务编码
        	rltdto.setInterfaceNo(responseMsg.getInterfaceNo());  //接口编码
        	rltdto.setRetCode(responseMsg.getRetCode());   //返回码        0000：成功  0001：失败  9999:日终处理中
        	rltdto.setRetTime(responseMsg.getRetTime());   //返回时间
        	rltdto.setRetMsg(responseMsg.getRetMsg());     //返回信息
        	return rltdto;
        }
    	return null;
    }
    
    /**
     * 获取风险金
     * @author zhangmi
     * @date  2017年5月8日
     * @param requestFundsRiskDTO
     * @return
     */
    public ResponseFundsRiskDTO getRiskInsertByCore(RequestFundsRiskDTO requestFundsRiskDTO){
    	String busiNoForInteract = iInteractAssist.getInteractNo();
    	Request4051DTO req = new Request4051DTO();
    	req.setcCode(requestFundsRiskDTO.getCooperorgCode());
    	req.setmCount(requestFundsRiskDTO.getmCount());
    	req.setBusiType(requestFundsRiskDTO.getBusiType());
    	
    	req.setFrontTransNo(busiNoForInteract);
    	req.setInterfaceNo((String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_FUNDS_RISK_INSERT_4051).get(CimsIrtUrlConstant.IRT_CODE));  //接口编码
        req.setBusiCode((String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_FUNDS_RISK_INSERT_4051).get(CimsIrtUrlConstant.IRT_BUSICODE)); //业务编码
        InteractEnsureDto ensureDto = new InteractEnsureDto();
        Response4051DTO responseMsg = interactClient.sendReqToCore(
                (String) CimsIrtUrlConstant.interactCfg.get(CimsIrtUrlConstant.IRT_FUNDS_RISK_INSERT_4051).get(
                        CimsIrtUrlConstant.IRT_URL), req, new TypeReference<ResponseMsg<Response4051DTO>>() {},
                ensureDto);
        if (responseMsg != null){
        	ResponseFundsRiskDTO  rltdto = ResponseFundsRiskDTO.successResponseFundsRiskDTO();
        	rltdto.setRiskList(responseMsg.getmCreditList());//风险金list
        	rltdto.setFrontTransNo(responseMsg.getFrontTransNo()); //合作机构交易流水号
        	rltdto.setCoreTransNo(responseMsg.getCoreTransNo());  //核心交易流水号
        	rltdto.setBusiCode(responseMsg.getBusiCode());  //业务编码
        	rltdto.setInterfaceNo(responseMsg.getInterfaceNo());  //接口编码
        	rltdto.setRetCode(responseMsg.getRetCode());   //返回码        0000：成功  0001：失败  9999:日终处理中
        	rltdto.setRetTime(responseMsg.getRetTime());   //返回时间
        	rltdto.setRetMsg(responseMsg.getRetMsg());     //返回信息
        	return rltdto;
        }
    	return null;
    }
}
